/*
 * Copyright 2011 JooKar (info@jookar.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.jookar.gcodecommithook;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

/**
 * Test class to test RegEx pattern.
 * <p>
 * Requirements:
 * <ul>
 * <li>We want to recognize the following strings:<ul>
 * <li>issue #</li>
 * <li>... more will follow</li>
 * </ul>
 * </li>
 * <li>Should be case insensitive</li>
 * <li>String can be at start of, end of or in the middle of a line</li>
 * <li>The nuber itself can only be numeric (duh..)</li>
 *</p>
 *
 * @author Joost A. Bloemsma
 */
public class PatternTest {
	String patt = "\\bIssue (\\d+)\\b";
    Pattern p = Pattern.compile(patt,Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
    @Test
    public void patternTest1() {
        assertTrue(test("Issue 1","patternTest1"));
    }

    @Test
    public void patternTest2() {
        assertTrue(test("Issue 1 asdf","patternTest2"));
    }

    @Test
    public void patternTest3() {
        assertTrue(test("sdfg Issue 1","patternTest3"));
    }

    @Test
    public void patternTest4() {
        assertTrue(test("issue 1","patternTest4"));
    }

    @Test
    public void patternTest5() {
        assertTrue(test("issue 1 Issue 4","patternTest5"));
    }

    @Test
    public void patternTest6() {
        assertFalse(test("iissue 1","patternTest6"));
    }

    @Test
    public void patternTest7() {
        assertFalse(test("issue 1w","patternTest7"));
    }

    @Test
    public void patternTest8() {
        assertTrue(test("issue 1.","patternTest8"));
    }

    @Test
    public void patternTest9() {
        assertTrue(test("Issue 1/ntest","patternTest9"));
    }


    private boolean test(String test, String name) {
        Matcher m = p.matcher(test);
        boolean b = false;
        System.out.println(name);
        while (m.find()) {
            b = true;
            System.out.println("Found: " + m.group() + " starting at " + m.start());
        }
        return b;
    }
}

